"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
// static静态属性
var People = /** @class */ (function () {
    function People(name, age) {
        this.age = 0;
        this.name = name;
        this.age = age;
        People.count++;
    }
    People.prototype.doEat = function () { };
    People.prototype.doStep = function () { };
    return People;
}());
var obj = new People('张三', 18);
obj.doEat();
// 静态方法
// 例如，此时公司要分装一个时间的类
var DateUtil = /** @class */ (function () {
    function DateUtil() {
    }
    DateUtil.formatDate = function () { }; // 格式化日期
    DateUtil.diffDateByDay = function () { }; // 几天前
    DateUtil.diffDateByHour = function () { }; // 几小时前
    return DateUtil;
}());
DateUtil.formatDate();
// 单件模式 -- 立即创建
var Car = /** @class */ (function () {
    function Car() {
        console.log('创建对象');
    }
    Car.prototype.doDrive = function () { };
    Car.car = new Car();
    return Car;
}());
console.log('abc'); // `类中的属性，在定义时，就会运行`，有默认值则立刻赋予。
var car1 = Car.car;
var car2 = Car.car;
console.log(car1 === car2); // true
// 单件模式  -- 调用时创建
var Car2 = /** @class */ (function () {
    function Car2() {
        console.log('创建对象');
    }
    Car2.getInstance = function () {
        if (!this.car) {
            this.car = new Car2();
        }
        return this.car;
    };
    Car2.prototype.doDrive = function () { };
    return Car2;
}());
console.log('abc'); // `类中的属性，在定义时，就会运行`，有默认值则立刻赋予。
var car3 = Car2.getInstance();
var car4 = Car2.getInstance();
console.log(car3 === car4); // true
// 类的get与set
var Human = /** @class */ (function () {
    function Human(name, address) {
        this.name = name;
        this.address = address;
    }
    Object.defineProperty(Human.prototype, "age", {
        get: function () {
            return this._age;
        },
        set: function (val) {
            if (val < 0 || val > 120) {
                throw Error('无效的年龄，请重新赋值');
            }
            this._age = val;
        },
        enumerable: false,
        configurable: true
    });
    return Human;
}());
var obj2 = new Human('张三', '广东省');
obj2.age = 100;
// 用类实现一个方法拦截器
var Man = /** @class */ (function () {
    function Man(name, age) {
        this.name = name;
        this.age = age;
    }
    Man.prototype.doEat = function (who, where) {
        console.log("who: ".concat(who, ", where: ").concat(where));
    };
    return Man;
}());
var dataProp = Object.getOwnPropertyDescriptor(Man.prototype, 'doEat');
var targetMethod = dataProp === null || dataProp === void 0 ? void 0 : dataProp.value;
dataProp.value = function () {
    var args = [];
    for (var _i = 0; _i < arguments.length; _i++) {
        args[_i] = arguments[_i];
    }
    console.log('开始计时');
    targetMethod.apply(this, args);
    console.log('结束计时');
};
dataProp === null || dataProp === void 0 ? void 0 : dataProp.value('王明', '酒吧');
